package com.nf.dao;

import com.nf.entity.Teacher;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

@Repository
@Scope("prototype")
public class TeacherDaoImpl implements TeacherDao{
    private SessionFactory factory=null;
    public List<Teacher> getAllTeacher() {
    List<Teacher> teacherList=null;
        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        factory = configuration.buildSessionFactory();
        Session session = factory.openSession();

        Query query = session.createQuery("from Teacher");
        teacherList = query.getResultList();

        session.close();
        factory.close();

        return teacherList;
    }
}
